﻿namespace WMS6.Services
{
    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Xml;
    using WMS6.BLL;
    using WMS6.DataEntity;

    public class CEAWebServiceWMS
    {
        private PubParasInfo pubParasInfo;

        public CEAWebServiceWMS()
        {
            this.pubParasInfo = null;
        }

        public CEAWebServiceWMS(string strUserName, string strPassword)
        {
            this.pubParasInfo = null;
            try
            {
                if (!this.UserAuthentication(strUserName, strUserName))
                {
                    throw new Exception("Error");
                }
                this.InitPubParasInfo();
            }
            catch (Exception)
            {
                throw new Exception("Error");
            }
        }

        public string DataSynchronizationASN(XmlDocument xdASN)
        {
            string strTemp = string.Empty;
            try
            {
                XmlDocument xmlDocument = xdASN;
                string strAction = xmlDocument.SelectNodes("Action")[0].Attributes["value"].Value;
                XmlNodeList student = xmlDocument.DocumentElement.ChildNodes;
                List<ReceiptInfo> receiptList = new List<ReceiptInfo>();
                foreach (XmlNode node in student)
                {
                    if (node.Name == "DATA_LIST")
                    {
                        ReceiptInfo receiptInfo = new ReceiptInfo();
                        if (node["EXTERNAL_RECEIPT_ID"] == null)
                        {
                            throw new Exception("文档中未匹配到 EXTERNAL_RECEIPT_ID");
                        }
                        if (string.IsNullOrEmpty(node["EXTERNAL_RECEIPT_ID"].Attributes["value"].Value))
                        {
                            throw new Exception("EXTERNAL_RECEIPT_ID 为必填 不能为空");
                        }
                        receiptInfo.ExternalReceiptID = node["EXTERNAL_RECEIPT_ID"].Attributes["value"].Value;
                        if (node["UDF4"] == null)
                        {
                            throw new Exception("文档中未匹配到 UDF4");
                        }
                        if (string.IsNullOrEmpty(node["UDF4"].Attributes["value"].Value))
                        {
                            throw new Exception("UDF4 为必填 不能为空");
                        }
                        receiptInfo.Udf4 = node["UDF4"].Attributes["value"].Value;
                        if (node["UDF3"] == null)
                        {
                            throw new Exception("文档中未匹配到 UDF3");
                        }
                        if (string.IsNullOrEmpty(node["UDF3"].Attributes["value"].Value))
                        {
                            throw new Exception("UDF3 为必填 不能为空");
                        }
                        receiptInfo.Udf3 = node["UDF3"].Attributes["value"].Value;
                        if (node["OWNER_ID"] == null)
                        {
                            throw new Exception("文档中未匹配到 OWNER_ID");
                        }
                        if (string.IsNullOrEmpty(node["OWNER_ID"].Attributes["value"].Value))
                        {
                            throw new Exception("OWNER_ID 为必填 不能为空");
                        }
                        receiptInfo.OwnerID = node["OWNER_ID"].Attributes["value"].Value;
                        DbConfigBLL dbConfigBll = new DbConfigBLL();
                        DbConfigInfo dbconfigInfo = new DbConfigInfo();
                        if (receiptInfo.OwnerID == "1000")
                        {
                            dbconfigInfo = (DbConfigInfo) dbConfigBll.GetDbConfigByDbLoginID("wh2");
                        }
                        else
                        {
                            dbconfigInfo = (DbConfigInfo) dbConfigBll.GetDbConfigByDbLoginID("wh1");
                        }
                        if (dbconfigInfo == null)
                        {
                            throw new Exception("无法匹配到" + receiptInfo.OwnerID + "公司所属的仓库名称");
                        }
                        this.pubParasInfo.CurrentWH = dbconfigInfo.WhDbID.ToString();
                        receiptInfo.WhID = dbconfigInfo.DbLoginID.ToString();
                        if (node["VENDOR_ID"] == null)
                        {
                            throw new Exception("文档中未匹配到 VENDOR_ID");
                        }
                        receiptInfo.VendorID = node["VENDOR_ID"].Attributes["value"].Value;
                        receiptInfo.ArrivalDate = DateTime.Now;
                        receiptInfo.Remark = "";
                        receiptInfo.ReceiptType = "Normal";
                        receiptInfo.PoID = "";
                        receiptInfo.PackingSlipNumber = "";
                        receiptInfo.Rma = "";
                        receiptInfo.ExpectedReceiptDate = DateTime.Now;
                        receiptInfo.ReceiptDate = DateTime.Now;
                        receiptInfo.OpenQty = 0M;
                        receiptInfo.Status = "New";
                        receiptInfo.ExternalReceiptId2 = "";
                        receiptInfo.WarehouseRef = "";
                        receiptInfo.AdviceNumber = "";
                        receiptInfo.TransportationMode = "LTL";
                        receiptInfo.IncoTerms = "CFR";
                        receiptInfo.PaymentTerm = "Cash";
                        receiptInfo.ContainerType = "DC20FT";
                        receiptInfo.ContainerQty = 0M;
                        receiptInfo.LottableMatchRequired = "N";
                        receiptInfo.IsPalletized = "N";
                        receiptInfo.IsActive = "Y";
                        receiptInfo.CoreReleaseID = "";
                        receiptInfo.IsDeclartion = "N";
                        receiptInfo.SAPAuthentication = "N";
                        receiptInfo.CreatedBy = "CEAWebService";
                        receiptInfo.CreatedDate = DateTime.Now;
                        receiptInfo.UpdatedBy = "CEAWebService";
                        receiptInfo.UpdatedDate = DateTime.Now;
                        receiptInfo.ReceiptDetailInfos = new List<ReceiptDetailInfo>();
                        XmlNodeList detail = node.ChildNodes;
                        int i = 0;
                        foreach (XmlNode detailnode in detail)
                        {
                            if (detailnode.Name == "DETAIL")
                            {
                                i++;
                                ReceiptDetailInfo receiptDetailInfo = new ReceiptDetailInfo();
                                receiptDetailInfo.ReceiptLot = new ReceiptLotInfo();
                                if (detailnode["SKU_ID"] == null)
                                {
                                    throw new Exception("文档中未匹配到 SKU_ID");
                                }
                                if (string.IsNullOrEmpty(detailnode["SKU_ID"].Attributes["value"].Value))
                                {
                                    throw new Exception("SKU_ID 为必填 不能为空");
                                }
                                receiptDetailInfo.SkuID = detailnode["SKU_ID"].Attributes["value"].Value;
                                if (detailnode["EXTERN_LINE_ID"] == null)
                                {
                                    throw new Exception("文档中未匹配到 EXTERN_LINE_ID");
                                }
                                if (string.IsNullOrEmpty(node["EXTERN_LINE_ID"].Attributes["value"].Value))
                                {
                                    throw new Exception("EXTERN_LINE_ID 为必填 不能为空");
                                }
                                receiptDetailInfo.ExternLineID = detailnode["EXTERN_LINE_ID"].Attributes["value"].Value;
                                if (detailnode["EXPECTED_QTY"] == null)
                                {
                                    throw new Exception("文档中未匹配到 EXPECTED_QTY");
                                }
                                if (string.IsNullOrEmpty(detailnode["EXPECTED_QTY"].Attributes["value"].Value))
                                {
                                    throw new Exception("EXPECTED_QTY 为必填 不能为空");
                                }
                                receiptDetailInfo.ExpectedQty = decimal.Parse(detailnode["EXPECTED_QTY"].Attributes["value"].Value);
                                if (detailnode["GROSS_WGT"] == null)
                                {
                                    throw new Exception("文档中未匹配到 GROSS_WGT");
                                }
                                if (string.IsNullOrEmpty(detailnode["GROSS_WGT"].Attributes["value"].Value))
                                {
                                    receiptDetailInfo.GrossWgt = 0f;
                                }
                                else
                                {
                                    receiptDetailInfo.GrossWgt = float.Parse(detailnode["GROSS_WGT"].Attributes["value"].Value);
                                }
                                if (detailnode["NET_WGT"] == null)
                                {
                                    throw new Exception("文档中未匹配到 NET_WGT");
                                }
                                if (string.IsNullOrEmpty(detailnode["NET_WGT"].Attributes["value"].Value))
                                {
                                    receiptDetailInfo.NetWgt = 0f;
                                }
                                else
                                {
                                    receiptDetailInfo.NetWgt = float.Parse(detailnode["NET_WGT"].Attributes["value"].Value);
                                }
                                if (detailnode["UNIT_PRICE"] == null)
                                {
                                    throw new Exception("文档中未匹配到 UNIT_PRICE");
                                }
                                if (string.IsNullOrEmpty(detailnode["UNIT_PRICE"].Attributes["value"].Value))
                                {
                                    receiptDetailInfo.UnitPrice = 0f;
                                }
                                else
                                {
                                    receiptDetailInfo.UnitPrice = float.Parse(detailnode["UNIT_PRICE"].Attributes["value"].Value);
                                }
                                receiptDetailInfo.ReceiptLot.LotAttr01 = "";
                                receiptDetailInfo.ReceiptLot.LotAttr02 = "";
                                receiptDetailInfo.ReceiptLot.LotAttr03 = "";
                                receiptDetailInfo.ReceiptLot.LotAttr04 = "";
                                receiptDetailInfo.ReceiptLot.LotAttr05 = "";
                                receiptDetailInfo.ReceiptLot.LotAttr06 = "";
                                receiptDetailInfo.ReceiptLot.LotAttr07 = "";
                                receiptDetailInfo.ReceiptLot.LotAttr08 = "";
                                receiptDetailInfo.ReceiptLot.LotAttr09 = "";
                                receiptDetailInfo.ReceiptLot.LotAttr10 = "";
                                receiptDetailInfo.Length = 0f;
                                receiptDetailInfo.Width = 0f;
                                receiptDetailInfo.Height = 0f;
                                receiptDetailInfo.Cube = 0f;
                                receiptDetailInfo.UomID = "EA";
                                receiptDetailInfo.VendorID = receiptInfo.VendorID;
                                receiptDetailInfo.ExtendedPrice = receiptDetailInfo.UnitPrice * float.Parse(receiptDetailInfo.ExpectedQty.ToString());
                                receiptDetailInfo.ReceiptLineID = i * 10;
                                receiptDetailInfo.OwnerID = receiptInfo.OwnerID;
                                receiptDetailInfo.ExternReceiptID = receiptInfo.ExternalReceiptID;
                                receiptDetailInfo.PoID = "";
                                receiptDetailInfo.PoLineID = 0;
                                receiptDetailInfo.AltSkuID = "";
                                receiptDetailInfo.LpnID = "";
                                receiptDetailInfo.Status = receiptInfo.Status;
                                receiptDetailInfo.ReceivedDate = DateTime.Now;
                                receiptDetailInfo.AdjustedQty = 0M;
                                receiptDetailInfo.ReceivedQty = 0M;
                                receiptDetailInfo.RejectedQty = 0M;
                                receiptDetailInfo.PackID = "STD";
                                receiptDetailInfo.ToLoc = "Stage";
                                receiptDetailInfo.ToLot = "";
                                receiptDetailInfo.ToLpnID = "";
                                receiptDetailInfo.ConditionCode = "OK";
                                receiptDetailInfo.ReceiptDate = receiptInfo.ReceiptDate;
                                receiptDetailInfo.ExternalLot = "";
                                receiptDetailInfo.CaseCnt = 0M;
                                receiptDetailInfo.InnerPack = 0M;
                                receiptDetailInfo.Pallet = 0M;
                                receiptDetailInfo.OtherUnit1 = 0f;
                                receiptDetailInfo.OtherUnit2 = 0f;
                                receiptDetailInfo.EffectiveDate = DateTime.Now;
                                receiptDetailInfo.QcRequired = "N";
                                receiptDetailInfo.QcInspectedQty = 0M;
                                receiptDetailInfo.QcAutoAdjust = "N";
                                receiptDetailInfo.DeclarationQty = 0M;
                                receiptDetailInfo.CreatedBy = "CEAWebService";
                                receiptDetailInfo.CreatedDate = DateTime.Now;
                                receiptDetailInfo.UpdatedBy = "CEAWebService";
                                receiptDetailInfo.UpdatedDate = DateTime.Now;
                                receiptInfo.ReceiptDetailInfos.Add(receiptDetailInfo);
                            }
                        }
                        receiptList.Add(receiptInfo);
                    }
                }
                CEABLL CEABLL = new CEABLL(this.pubParasInfo);
                if (strAction == "INSERT")
                {
                    strTemp = CEABLL.InsertReceiptByWebService(receiptList);
                }
            }
            catch (Exception ex)
            {
                EdiLogInfo edilogInfo = new EdiLogInfo();
                edilogInfo.WhID = "";
                edilogInfo.LogDate = DateTime.Now;
                edilogInfo.IsSuccess = "异常";
                edilogInfo.LogDescr = "XML数据组织错误:" + ex.Message;
                edilogInfo.UserID = "CEAWebService";
                edilogInfo.Udf1 = "接口数据组织";
                edilogInfo.Udf3 = "入库单数据";
                new EDIService().InsertEdiLogInfo(edilogInfo);
                strTemp = ex.Message;
            }
            return strTemp;
        }

        public string DataSynchronizationCustomer(XmlDocument xdCustomer)
        {
            string strTemp = string.Empty;
            try
            {
                XmlDocument xmlDocument = xdCustomer;
                string strAction = xmlDocument.SelectNodes("Action")[0].Attributes["value"].Value;
                XmlNodeList student = xmlDocument.DocumentElement.ChildNodes;
                List<CustomerInfo> custonerList = new List<CustomerInfo>();
                foreach (XmlNode node in student)
                {
                    if (node.Name == "DATA_LIST")
                    {
                        CustomerInfo customerInfo = new CustomerInfo();
                        if (node["CUSTOMER_ID"] == null)
                        {
                            throw new Exception("文档中未匹配到 CUSTOMER_ID");
                        }
                        if (string.IsNullOrEmpty(node["CUSTOMER_ID"].Attributes["value"].Value))
                        {
                            throw new Exception("CUSTOMER_ID 为必填 不能为空");
                        }
                        customerInfo.CustomerID = node["CUSTOMER_ID"].Attributes["value"].Value;
                        if (node["COMPANY"] == null)
                        {
                            throw new Exception("文档中未匹配到 COMPANY");
                        }
                        customerInfo.Company = node["COMPANY"].Attributes["value"].Value;
                        if (node["IS_ACTIVE"] == null)
                        {
                            throw new Exception("文档中未匹配到 IS_ACTIVE");
                        }
                        if (string.IsNullOrEmpty(node["IS_ACTIVE"].Attributes["value"].Value))
                        {
                            customerInfo.IsActive = "Y";
                        }
                        else
                        {
                            customerInfo.IsActive = node["IS_ACTIVE"].Attributes["value"].Value;
                        }
                        if (node["ADDRESS1"] == null)
                        {
                            throw new Exception("文档中未匹配到 ADDRESS1");
                        }
                        customerInfo.Address = node["ADDRESS1"].Attributes["value"].Value;
                        if (node["ADDRESS2"] == null)
                        {
                            throw new Exception("文档中未匹配到 ADDRESS2");
                        }
                        customerInfo.Address = customerInfo.Address + node["ADDRESS2"].Attributes["value"].Value;
                        if (node["ADDRESS3"] == null)
                        {
                            throw new Exception("文档中未匹配到 ADDRESS3");
                        }
                        customerInfo.Address = customerInfo.Address + ";" + node["ADDRESS3"].Attributes["value"].Value;
                        if (node["ADDRESS4"] == null)
                        {
                            throw new Exception("文档中未匹配到 ADDRESS4");
                        }
                        customerInfo.Address = customerInfo.Address + node["ADDRESS4"].Attributes["value"].Value;
                        if (node["UDF1"] == null)
                        {
                            throw new Exception("文档中未匹配到 UDF1");
                        }
                        customerInfo.Udf1 = node["UDF1"].Attributes["value"].Value;
                        if (node["UDF2"] == null)
                        {
                            throw new Exception("文档中未匹配到 UDF2");
                        }
                        customerInfo.Udf2 = node["UDF2"].Attributes["value"].Value;
                        if (node["UDF3"] == null)
                        {
                            throw new Exception("文档中未匹配到 UDF3");
                        }
                        customerInfo.Udf3 = node["UDF3"].Attributes["value"].Value;
                        if (node["UDF4"] == null)
                        {
                            throw new Exception("文档中未匹配到 UDF4");
                        }
                        customerInfo.Udf4 = node["UDF4"].Attributes["value"].Value;
                        if (node["UDF5"] == null)
                        {
                            throw new Exception("文档中未匹配到 UDF5");
                        }
                        customerInfo.Udf5 = node["UDF5"].Attributes["value"].Value;
                        customerInfo.BCity = "";
                        customerInfo.BState = "";
                        customerInfo.BContact1 = "";
                        customerInfo.BContact2 = "";
                        customerInfo.BCountry = "";
                        customerInfo.BZip = "";
                        customerInfo.BPhone1 = "";
                        customerInfo.BPhone2 = "";
                        customerInfo.BAddress = "";
                        customerInfo.BFax1 = "";
                        customerInfo.BFax2 = "";
                        customerInfo.BEmail1 = "";
                        customerInfo.BEmail2 = "";
                        customerInfo.Udf6 = "";
                        customerInfo.Udf7 = "";
                        customerInfo.Udf8 = "";
                        customerInfo.Udf9 = "";
                        customerInfo.Udf10 = "";
                        customerInfo.CreatedBy = "CEAWebService";
                        customerInfo.CreatedDate = DateTime.Now;
                        customerInfo.UpdatedBy = "CEAWebService";
                        customerInfo.UpdatedDate = DateTime.Now;
                        custonerList.Add(customerInfo);
                    }
                }
                CustomerBLL customerBLL = new CustomerBLL(this.pubParasInfo);
                switch (strAction)
                {
                    case "INSERT":
                        return customerBLL.InsertCustomerByWebService(custonerList);

                    case "UPDATE":
                        strTemp = customerBLL.UpdateCustomerByWebService(custonerList);
                        break;
                }
            }
            catch (Exception ex)
            {
                EdiLogInfo edilogInfo = new EdiLogInfo();
                edilogInfo.WhID = "";
                edilogInfo.LogDate = DateTime.Now;
                edilogInfo.IsSuccess = "异常";
                edilogInfo.LogDescr = "XML数据组织错误:" + ex.Message;
                edilogInfo.UserID = "CEAWebService";
                edilogInfo.Udf1 = "接口数据组织";
                edilogInfo.Udf3 = "客户资料资料";
                new EDIService().InsertEdiLogInfo(edilogInfo);
                strTemp = ex.Message;
            }
            return strTemp;
        }

        public string DataSynchronizationOrders(XmlDocument xdOrders)
        {
            string strTemp = string.Empty;
            try
            {
                XmlDocument xmlDocument = xdOrders;
                string strAction = xmlDocument.SelectNodes("Action")[0].Attributes["value"].Value;
                XmlNodeList student = xmlDocument.DocumentElement.ChildNodes;
                List<OrdersInfo> ordersList = new List<OrdersInfo>();
                foreach (XmlNode node in student)
                {
                    if (node.Name == "DATA_LIST")
                    {
                        OrdersInfo ordersInfo = new OrdersInfo();
                        if (node["EXTERN_ORDER_ID"] == null)
                        {
                            throw new Exception("文档中未匹配到 EXTERN_ORDER_ID");
                        }
                        if (string.IsNullOrEmpty(node["EXTERN_ORDER_ID"].Attributes["value"].Value))
                        {
                            throw new Exception("EXTERN_ORDER_ID 为必填 不能为空");
                        }
                        ordersInfo.ExternOrderID = node["EXTERN_ORDER_ID"].Attributes["value"].Value;
                        if (node["OWNER_ID"] == null)
                        {
                            throw new Exception("文档中未匹配到 OWNER_ID");
                        }
                        if (string.IsNullOrEmpty(node["OWNER_ID"].Attributes["value"].Value))
                        {
                            throw new Exception("OWNER_ID 为必填 不能为空");
                        }
                        ordersInfo.OwnerID = node["OWNER_ID"].Attributes["value"].Value;
                        DbConfigBLL dbConfigBll = new DbConfigBLL();
                        DbConfigInfo dbconfigInfo = new DbConfigInfo();
                        if (ordersInfo.OwnerID == "1000")
                        {
                            dbconfigInfo = (DbConfigInfo) dbConfigBll.GetDbConfigByDbLoginID("wh2");
                        }
                        else
                        {
                            dbconfigInfo = (DbConfigInfo) dbConfigBll.GetDbConfigByDbLoginID("wh1");
                        }
                        if (dbconfigInfo == null)
                        {
                            throw new Exception("无法匹配到" + ordersInfo.OwnerID + "公司所属的仓库名称");
                        }
                        ordersInfo.WhID = dbconfigInfo.DbLoginID.ToString() + ".";
                        if (node["TYPE"] == null)
                        {
                            throw new Exception("文档中未匹配到 TYPE");
                        }
                        if (string.IsNullOrEmpty(node["TYPE"].Attributes["value"].Value))
                        {
                            throw new Exception("TYPE 为必填 不能为空");
                        }
                        ordersInfo.Udf10 = node["TYPE"].Attributes["value"].Value;
                        if (node["REQUEST_SHIP_DATE"] == null)
                        {
                            throw new Exception("文档中未匹配到 DELIVERY_DATE");
                        }
                        if (string.IsNullOrEmpty(node["REQUEST_SHIP_DATE"].Attributes["value"].Value))
                        {
                            ordersInfo.RequestedShipDate = DateTime.Now;
                        }
                        else
                        {
                            ordersInfo.RequestedShipDate = DateTime.Parse(node["REQUEST_SHIP_DATE"].Attributes["value"].Value);
                        }
                        if (node["CONSIGNEE_ID"] == null)
                        {
                            throw new Exception("文档中未匹配到 CONSIGNEE_ID");
                        }
                        ordersInfo.ConsigneeID = node["CONSIGNEE_ID"].Attributes["value"].Value;
                        if (node["REMARK"] == null)
                        {
                            throw new Exception("文档中未匹配到 REMARK");
                        }
                        ordersInfo.Remark = node["REMARK"].Attributes["value"].Value;
                        ordersInfo.Type = "Standard";
                        ordersInfo.OrderDate = DateTime.Now;
                        ordersInfo.Priority = "3";
                        ordersInfo.OrderGroup = "";
                        ordersInfo.OpenQty = 0M;
                        ordersInfo.Status = "New";
                        ordersInfo.BillToID = "";
                        ordersInfo.DepartureDate = DateTime.Now;
                        ordersInfo.Door = "";
                        ordersInfo.Route = "";
                        ordersInfo.Stop = "";
                        ordersInfo.TransportationMode = "LTL";
                        ordersInfo.IncoTerms = "CFR";
                        ordersInfo.ContainerType = "DC20FT";
                        ordersInfo.ContainerQty = 0M;
                        ordersInfo.HandlingType = "Standard";
                        ordersInfo.BatchFlag = "N";
                        ordersInfo.ShipTogether = "N";
                        ordersInfo.EnablePacking = "N";
                        ordersInfo.OrderValue = 0M;
                        ordersInfo.UpdateSource = "";
                        ordersInfo.IsActive = "Y";
                        ordersInfo.CreatedBy = "CEAWebService";
                        ordersInfo.CreatedDate = DateTime.Now;
                        ordersInfo.UpdatedBy = "CEAWebService";
                        ordersInfo.UpdatedDate = DateTime.Now;
                        ordersInfo.CoreReleaseID = "";
                        ordersInfo.IsDeclartion = "N";
                        ordersInfo.ActualWeight = 0M;
                        ordersInfo.PrintCount = 0;
                        ordersInfo.IsICancel = "N";
                        ordersInfo.IsCod = "N";
                        ordersInfo.IsInvoicePrint = "N";
                        ordersInfo.OrderDetailInfos = new List<OrderDetailInfo>();
                        XmlNodeList detail = node.ChildNodes;
                        int i = 0;
                        foreach (XmlNode detailnode in detail)
                        {
                            if (detailnode.Name == "DETAIL")
                            {
                                i++;
                                OrderDetailInfo orderDetailInfo = new OrderDetailInfo();
                                if (detailnode["SKU_ID"] == null)
                                {
                                    throw new Exception("文档中未匹配到 SKU_ID");
                                }
                                if (string.IsNullOrEmpty(detailnode["SKU_ID"].Attributes["value"].Value))
                                {
                                    throw new Exception("SKU_ID 为必填 不能为空");
                                }
                                orderDetailInfo.SkuID = detailnode["SKU_ID"].Attributes["value"].Value;
                                if (detailnode["ORIGINAL_QTY"] == null)
                                {
                                    throw new Exception("文档中未匹配到 ORIGINAL_QTY");
                                }
                                if (string.IsNullOrEmpty(detailnode["ORIGINAL_QTY"].Attributes["value"].Value))
                                {
                                    throw new Exception("ORIGINAL_QTY 为必填 不能为空");
                                }
                                orderDetailInfo.OriginalQty = decimal.Parse(detailnode["ORIGINAL_QTY"].Attributes["value"].Value);
                                if (detailnode["EXTERN_ORDER_LINE_ID"] == null)
                                {
                                    throw new Exception("文档中未匹配到 EXTERN_ORDER_LINE_ID");
                                }
                                if (string.IsNullOrEmpty(detailnode["EXTERN_ORDER_LINE_ID"].Attributes["value"].Value))
                                {
                                    throw new Exception("EXTERN_ORDER_LINE_ID 为必填 不能为空");
                                }
                                orderDetailInfo.ExternLineID = detailnode["EXTERN_ORDER_LINE_ID"].Attributes["value"].Value;
                                if (node["UDF1"] == null)
                                {
                                    throw new Exception("文档中未匹配到 UDF1");
                                }
                                orderDetailInfo.Udf1 = node["UDF1"].Attributes["value"].Value;
                                if (node["UDF2"] == null)
                                {
                                    throw new Exception("文档中未匹配到 UDF2");
                                }
                                orderDetailInfo.Udf2 = node["UDF2"].Attributes["value"].Value;
                                if (node["UDF3"] == null)
                                {
                                    throw new Exception("文档中未匹配到 UDF3");
                                }
                                orderDetailInfo.Udf3 = node["UDF3"].Attributes["value"].Value;
                                if (node["UDF4"] == null)
                                {
                                    throw new Exception("文档中未匹配到 UDF4");
                                }
                                orderDetailInfo.Udf4 = node["UDF4"].Attributes["value"].Value;
                                if (node["UDF5"] == null)
                                {
                                    throw new Exception("文档中未匹配到 UDF5");
                                }
                                orderDetailInfo.Udf5 = node["UDF5"].Attributes["value"].Value;
                                orderDetailInfo.LotAttr01 = "";
                                orderDetailInfo.LotAttr02 = "";
                                orderDetailInfo.LotAttr03 = "";
                                orderDetailInfo.LotAttr04 = "";
                                orderDetailInfo.LotAttr05 = "";
                                orderDetailInfo.LotAttr06 = "";
                                orderDetailInfo.LotAttr07 = "";
                                orderDetailInfo.LotAttr08 = "";
                                orderDetailInfo.LotAttr09 = "";
                                orderDetailInfo.LotAttr10 = "";
                                orderDetailInfo.UomID = "EA";
                                orderDetailInfo.Length = 0f;
                                orderDetailInfo.Width = 0f;
                                orderDetailInfo.Height = 0f;
                                orderDetailInfo.Cube = 0f;
                                orderDetailInfo.GrossWGT = 0f;
                                orderDetailInfo.NetWGT = 0f;
                                orderDetailInfo.UnitPrice = 0.0;
                                orderDetailInfo.ExtendedPrice = 0.0;
                                orderDetailInfo.VendorID = "";
                                orderDetailInfo.LineID = i * 10;
                                orderDetailInfo.ExternOrderID = ordersInfo.ExternOrderID;
                                orderDetailInfo.AltSkuID = "";
                                orderDetailInfo.OwnerID = ordersInfo.OwnerID;
                                orderDetailInfo.OpenQty = 0M;
                                orderDetailInfo.ShippedQty = 0M;
                                orderDetailInfo.AdjustedQty = 0M;
                                orderDetailInfo.PreallocatedQty = 0M;
                                orderDetailInfo.AllocatedQty = 0M;
                                orderDetailInfo.PickedQty = 0M;
                                orderDetailInfo.PackID = "STD";
                                orderDetailInfo.PickCode = "";
                                orderDetailInfo.CartonGroup = "";
                                orderDetailInfo.LpnID = "";
                                orderDetailInfo.Status = "New";
                                orderDetailInfo.Tax01 = 0.0;
                                orderDetailInfo.Tax02 = 0.0;
                                orderDetailInfo.UpdateSource = "";
                                orderDetailInfo.ProductWeight = 0.0;
                                orderDetailInfo.ProductCube = 0.0;
                                orderDetailInfo.CartonQtyBreak = 0;
                                orderDetailInfo.QcRequired = "N";
                                orderDetailInfo.QcAutoAdjust = "N";
                                orderDetailInfo.ShipGroup01 = "Y";
                                orderDetailInfo.ShipGroup02 = "N";
                                orderDetailInfo.ShipGroup03 = "N";
                                orderDetailInfo.IsSubstitute = 0;
                                orderDetailInfo.OkToSubstitute = 0;
                                orderDetailInfo.AllocateRuleID = "STD";
                                orderDetailInfo.PreallocateRuleID = "STD";
                                orderDetailInfo.SkuRotation = "Lot";
                                orderDetailInfo.ShelfLife = 0;
                                orderDetailInfo.ComponentQty = 0M;
                                orderDetailInfo.Lot = "";
                                orderDetailInfo.EffectiveDate = DateTime.Now;
                                orderDetailInfo.OrigCaseQty = 0M;
                                orderDetailInfo.OrigPalletQty = 0M;
                                orderDetailInfo.QtyIntransit = 0M;
                                orderDetailInfo.WpReleased = "N";
                                orderDetailInfo.MinShipperCent = 0;
                                orderDetailInfo.CreatedBy = "CEAWebService";
                                orderDetailInfo.CreatedDate = DateTime.Now;
                                orderDetailInfo.UpdatedBy = "CEAWebService";
                                orderDetailInfo.UpdatedDate = DateTime.Now;
                                orderDetailInfo.DeclarationQty = 0M;
                                orderDetailInfo.NumberLost = 0M;
                                orderDetailInfo.ReceivedQty = 0M;
                                orderDetailInfo.BatchFlag = "N";
                                ordersInfo.OrderDetailInfos.Add(orderDetailInfo);
                            }
                        }
                        ordersList.Add(ordersInfo);
                    }
                }
                CEABLL CEABLL = new CEABLL(this.pubParasInfo);
                if (strAction == "INSERT")
                {
                    strTemp = CEABLL.InsertOrdersByWebService(ordersList);
                }
            }
            catch (Exception ex)
            {
                EdiLogInfo edilogInfo = new EdiLogInfo();
                edilogInfo.WhID = "";
                edilogInfo.LogDate = DateTime.Now;
                edilogInfo.IsSuccess = "异常";
                edilogInfo.LogDescr = "XML数据组织错误:" + ex.Message;
                edilogInfo.UserID = "CEAWebService";
                edilogInfo.Udf1 = "接口数据组织";
                edilogInfo.Udf3 = "发货订单数据";
                new EDIService().InsertEdiLogInfo(edilogInfo);
                strTemp = ex.Message;
            }
            return strTemp;
        }

        public string DataSynchronizationSales(XmlDocument xdSales)
        {
            string strTemp = string.Empty;
            try
            {
                XmlDocument xmlDocument = xdSales;
                string strAction = xmlDocument.SelectNodes("Action")[0].Attributes["value"].Value;
                XmlNodeList student = xmlDocument.DocumentElement.ChildNodes;
                List<ReceiptInfo> receiptList = new List<ReceiptInfo>();
                List<OrdersInfo> ordersList = new List<OrdersInfo>();
                foreach (XmlNode node in student)
                {
                    if (node.Name == "DATA_LIST")
                    {
                        if (node["TYPE"] == null)
                        {
                            throw new Exception("文档中未匹配到 TYPE");
                        }
                        if (string.IsNullOrEmpty(node["TYPE"].Attributes["value"].Value))
                        {
                            throw new Exception("TYPE 为必填 不能为空");
                        }
                        switch (node["TYPE"].Attributes["value"].Value)
                        {
                            case "LR":
                                receiptList.Add(this.SetReceiptInfo(node, "1000"));
                                break;

                            case "ZLR":
                                ordersList.Add(this.SetOrdersInfo(node, "1000", "1000"));
                                break;

                            case "VLR":
                                receiptList.Add(this.SetReceiptInfo(node, "9000"));
                                break;

                            case "VZLR":
                                ordersList.Add(this.SetOrdersInfo(node, "9000", "9000"));
                                break;

                            case "TILR":
                                ordersList.Add(this.SetOrdersInfo(node, "1000", "3000"));
                                break;

                            case "TLR":
                                receiptList.Add(this.SetReceiptInfo(node, "3000"));
                                break;

                            case "TZLR":
                                ordersList.Add(this.SetOrdersInfo(node, "3000", "3000"));
                                break;
                        }
                    }
                }
                CEABLL CEABLL = new CEABLL(this.pubParasInfo);
                if ((ordersList.Count > 0) && (strAction == "INSERT"))
                {
                    strTemp = CEABLL.InsertOrdersByWebService(ordersList);
                }
                if (receiptList.Count <= 0)
                {
                    return strTemp;
                }
                if (strAction == "INSERT")
                {
                    strTemp = CEABLL.InsertReceiptByWebService(receiptList);
                }
            }
            catch (Exception ex)
            {
                EdiLogInfo edilogInfo = new EdiLogInfo();
                edilogInfo.WhID = "";
                edilogInfo.LogDate = DateTime.Now;
                edilogInfo.IsSuccess = "异常";
                edilogInfo.LogDescr = "XML数据组织错误:" + ex.Message;
                edilogInfo.UserID = "CEAWebService";
                edilogInfo.Udf1 = "接口数据组织";
                edilogInfo.Udf3 = "销售退回数据";
                new EDIService().InsertEdiLogInfo(edilogInfo);
                strTemp = ex.Message;
            }
            return strTemp;
        }

        public string DataSynchronizationSku(XmlDocument xdSku)
        {
            string strTemp = string.Empty;
            try
            {
                XmlDocument xmlDocument = xdSku;
                string strAction = xmlDocument.SelectNodes("Action")[0].Attributes["value"].Value;
                XmlNodeList student = xmlDocument.DocumentElement.ChildNodes;
                List<SkuInfo> skuList = new List<SkuInfo>();
                foreach (XmlNode node in student)
                {
                    if (node.Name == "DATA_LIST")
                    {
                        SkuInfo skuInfo = new SkuInfo();
                        if (node["IS_ACTIVE"] == null)
                        {
                            throw new Exception("文档中未匹配到 IS_ACTIVE ");
                        }
                        if (string.IsNullOrEmpty(node["IS_ACTIVE"].Attributes["value"].Value))
                        {
                            skuInfo.IsActive = "Y";
                        }
                        else
                        {
                            skuInfo.IsActive = node["IS_ACTIVE"].Attributes["value"].Value;
                        }
                        if (node["SKU_ID"] == null)
                        {
                            throw new Exception("文档中未匹配到 SKU_ID ");
                        }
                        if (string.IsNullOrEmpty(node["SKU_ID"].Attributes["value"].Value))
                        {
                            throw new Exception("SKU_ID 为必填 不能为空");
                        }
                        skuInfo.SkuID = node["SKU_ID"].Attributes["value"].Value;
                        if (node["SKU_CLASS_ID"] == null)
                        {
                            throw new Exception("文档中未匹配到 SKU_CLASS_ID ");
                        }
                        skuInfo.SkuClassID = node["SKU_CLASS_ID"].Attributes["value"].Value;
                        if (node["SKU_CLASS_DESCR"] == null)
                        {
                            throw new Exception("文档中未匹配到 SKU_CLASS_DESCR ");
                        }
                        skuInfo.Udf9 = node["SKU_CLASS_DESCR"].Attributes["value"].Value;
                        if (node["DESCR"] == null)
                        {
                            throw new Exception("文档中未匹配到 DESCR ");
                        }
                        skuInfo.Descr = node["DESCR"].Attributes["value"].Value;
                        if (node["SKU_STYLE"] == null)
                        {
                            throw new Exception("文档中未匹配到 SKU_STYLE ");
                        }
                        skuInfo.SkuStyle = node["SKU_STYLE"].Attributes["value"].Value;
                        if (node["UDF1"] == null)
                        {
                            throw new Exception("文档中未匹配到 UDF1 ");
                        }
                        skuInfo.Udf1 = node["UDF1"].Attributes["value"].Value;
                        if (node["UDF2"] == null)
                        {
                            throw new Exception("文档中未匹配到 UDF2 ");
                        }
                        skuInfo.Udf2 = node["UDF2"].Attributes["value"].Value;
                        if (node["UDF3"] == null)
                        {
                            throw new Exception("文档中未匹配到 UDF3 ");
                        }
                        skuInfo.Udf3 = node["UDF3"].Attributes["value"].Value;
                        if (node["UDF4"] == null)
                        {
                            throw new Exception("文档中未匹配到 UDF4 ");
                        }
                        skuInfo.Udf4 = node["UDF4"].Attributes["value"].Value;
                        if (node["UDF5"] == null)
                        {
                            throw new Exception("文档中未匹配到 UDF5 ");
                        }
                        skuInfo.Udf5 = node["UDF5"].Attributes["value"].Value;
                        if (node["SKU_GROUP"] == null)
                        {
                            throw new Exception("文档中未匹配到 SKU_GROUP ");
                        }
                        skuInfo.SkuGroup = node["SKU_GROUP"].Attributes["value"].Value;
                        if (node["SKU_GROUP2"] == null)
                        {
                            throw new Exception("文档中未匹配到 SKU_GROUP2 ");
                        }
                        skuInfo.SkuGroup2 = node["SKU_GROUP2"].Attributes["value"].Value;
                        if (node["ALT_SKU_ID"] == null)
                        {
                            throw new Exception("文档中未匹配到 ALT_SKU_ID ");
                        }
                        skuInfo.Udf10 = node["ALT_SKU_ID"].Attributes["value"].Value;
                        if (node["REORDER_QTY"] == null)
                        {
                            throw new Exception("文档中未匹配到 REORDER_QTY ");
                        }
                        skuInfo.ReorderQty = decimal.Parse(node["REORDER_QTY"].Attributes["value"].Value);
                        skuInfo.ShelfLifeIndicator = "N";
                        skuInfo.IsSalePromption = "N";
                        skuInfo.PackID = "STD";
                        skuInfo.HazmatCode = "";
                        skuInfo.ShelfLifeCodeType = "E";
                        skuInfo.Length = 0f;
                        skuInfo.Width = 0f;
                        skuInfo.Height = 0f;
                        skuInfo.Cube = 0f;
                        skuInfo.GrossWgt = 0f;
                        skuInfo.NetWgt = 0f;
                        skuInfo.OwnerID = "";
                        skuInfo.Descr2 = "";
                        skuInfo.CostPrice = 0M;
                        skuInfo.SalePrice = 0M;
                        skuInfo.CustomSkuNo = "";
                        skuInfo.ShelfLifeOnReceiving = 0;
                        skuInfo.CartonGroup = "";
                        skuInfo.CountryOfOrigin = "";
                        skuInfo.ShelfLife = 0;
                        skuInfo.LotTemplateID = "STD";
                        skuInfo.DaysToExpire = 0;
                        skuInfo.TareWgt = 0f;
                        skuInfo.SkuSize = "";
                        skuInfo.SkuColor = "";
                        skuInfo.PutawayLoc = "Stage";
                        skuInfo.NetPrice = 0M;
                        skuInfo.DefaultInUom = "";
                        skuInfo.DefaultOutUom = "";
                        skuInfo.RfDefaultPack = "";
                        skuInfo.ReceiptValidationTemplate = "";
                        skuInfo.ReceiptValidationID = "STD";
                        skuInfo.PutawayRuleID = "STD";
                        skuInfo.CalculatePutawayLocation = "Manual";
                        skuInfo.PreallocateRuleID = "STD";
                        skuInfo.AllocateRuleID = "STD";
                        skuInfo.RotationRuleID = "STD";
                        skuInfo.Abc = "";
                        skuInfo.CcDiscrepanCyrule = "";
                        skuInfo.LastCycleCount = DateTime.Now;
                        skuInfo.QcLoc = "";
                        skuInfo.StdOrderCost = 0f;
                        skuInfo.CarryCost = 0f;
                        skuInfo.ReorderPoint = 0;
                        skuInfo.CycleCountFrequency = 0;
                        skuInfo.ZoneID = "";
                        skuInfo.ReceiptInspectionLoc = "QC";
                        skuInfo.QcLocOut = "PICKTO";
                        skuInfo.ReturnsLoc = "RETURN";
                        skuInfo.MinQty = 0M;
                        skuInfo.MaxQty = 0M;
                        skuInfo.Udf6 = "";
                        skuInfo.Udf7 = "";
                        skuInfo.Udf8 = "";
                        skuInfo.BUdf1 = "";
                        skuInfo.BUdf2 = "";
                        skuInfo.BUdf3 = "";
                        skuInfo.BUdf4 = "";
                        skuInfo.BUdf5 = "";
                        skuInfo.BUdf6 = "";
                        skuInfo.BUdf7 = "";
                        skuInfo.BUdf8 = "";
                        skuInfo.BUdf9 = "";
                        skuInfo.BUdf10 = "";
                        skuInfo.ItemNoID = "";
                        skuInfo.Remark1 = "";
                        skuInfo.TariffID = "STD";
                        skuInfo.TransportMode = "Parcel";
                        skuInfo.FreightClass = "Heavy";
                        skuInfo.ReceiptValidationTemplate = "";
                        skuInfo.CreatedBy = "WebService";
                        skuInfo.UpdatedBy = "WebService";
                        skuInfo.CreatedDate = DateTime.Now;
                        skuInfo.UpdatedDate = DateTime.Now;
                        skuList.Add(skuInfo);
                    }
                }
                SkuBLL skubll = new SkuBLL(this.pubParasInfo);
                switch (strAction)
                {
                    case "INSERT":
                        return skubll.InsertSkuByWebService(skuList);

                    case "UPDATE":
                        strTemp = skubll.UpdateSkuWebService(skuList);
                        break;
                }
            }
            catch (Exception ex)
            {
                EdiLogInfo edilogInfo = new EdiLogInfo();
                edilogInfo.WhID = "";
                edilogInfo.LogDate = DateTime.Now;
                edilogInfo.IsSuccess = "异常";
                edilogInfo.LogDescr = "XML数据组织错误:" + ex.Message;
                edilogInfo.UserID = "CEAWebService";
                edilogInfo.Udf1 = "接口数据组织";
                edilogInfo.Udf3 = "货品资料";
                new EDIService().InsertEdiLogInfo(edilogInfo);
                strTemp = ex.Message;
            }
            return strTemp;
        }

        public string DataSynchronizationVendor(XmlDocument xdVendor)
        {
            string strTemp = string.Empty;
            try
            {
                XmlDocument xmlDocument = xdVendor;
                string strAction = xmlDocument.SelectNodes("Action")[0].Attributes["value"].Value;
                XmlNodeList student = xmlDocument.DocumentElement.ChildNodes;
                List<VendorInfo> vendorList = new List<VendorInfo>();
                foreach (XmlNode node in student)
                {
                    if (node.Name == "DATA_LIST")
                    {
                        VendorInfo vendorInfo = new VendorInfo();
                        if (node["VENDOR_ID"] == null)
                        {
                            throw new Exception("文档中未匹配到 VENDOR_ID");
                        }
                        if (string.IsNullOrEmpty(node["VENDOR_ID"].Attributes["value"].Value))
                        {
                            throw new Exception("VENDOR_ID 为必填 不能为空");
                        }
                        vendorInfo.VendorID = node["VENDOR_ID"].Attributes["value"].Value;
                        if (node["COUNTRY"] == null)
                        {
                            throw new Exception("文档中未匹配到 COUNTRY");
                        }
                        vendorInfo.Country = node["COUNTRY"].Attributes["value"].Value;
                        if (node["IS_ACTIVE"] == null)
                        {
                            throw new Exception("文档中未匹配到 IS_ACTIVE");
                        }
                        if (string.IsNullOrEmpty(node["IS_ACTIVE"].Attributes["value"].Value))
                        {
                            vendorInfo.IsActive = "Y";
                        }
                        else
                        {
                            vendorInfo.IsActive = node["IS_ACTIVE"].Attributes["value"].Value;
                        }
                        if (node["UDF1"] == null)
                        {
                            throw new Exception("文档中未匹配到 UDF1");
                        }
                        vendorInfo.Udf1 = node["UDF1"].Attributes["value"].Value;
                        if (node["UDF2"] == null)
                        {
                            throw new Exception("文档中未匹配到 UDF2");
                        }
                        vendorInfo.Udf2 = node["UDF2"].Attributes["value"].Value;
                        if (node["UDF3"] == null)
                        {
                            throw new Exception("文档中未匹配到 UDF3");
                        }
                        vendorInfo.Udf3 = node["UDF3"].Attributes["value"].Value;
                        if (node["UDF4"] == null)
                        {
                            throw new Exception("文档中未匹配到 UDF4");
                        }
                        vendorInfo.Udf4 = node["UDF4"].Attributes["value"].Value;
                        vendorInfo.Company = vendorInfo.VendorID;
                        vendorInfo.BCity = "";
                        vendorInfo.BState = "";
                        vendorInfo.BContact1 = "";
                        vendorInfo.BContact2 = "";
                        vendorInfo.BCountry = "";
                        vendorInfo.BZip = "";
                        vendorInfo.BPhone1 = "";
                        vendorInfo.BPhone2 = "";
                        vendorInfo.BAddress = "";
                        vendorInfo.BFax1 = "";
                        vendorInfo.BFax2 = "";
                        vendorInfo.BEmail1 = "";
                        vendorInfo.BEmail2 = "";
                        vendorInfo.Udf5 = "";
                        vendorInfo.Udf6 = "";
                        vendorInfo.Udf7 = "";
                        vendorInfo.Udf8 = "";
                        vendorInfo.Udf9 = "";
                        vendorInfo.Udf10 = "";
                        vendorInfo.CreatedBy = "CEAWebService";
                        vendorInfo.CreatedDate = DateTime.Now;
                        vendorInfo.UpdatedBy = "CEAWebService";
                        vendorInfo.UpdatedDate = DateTime.Now;
                        vendorList.Add(vendorInfo);
                    }
                }
                VendorBLL vendorBLL = new VendorBLL(this.pubParasInfo);
                switch (strAction)
                {
                    case "INSERT":
                        return vendorBLL.InsertVendorByWebService(vendorList);

                    case "UPDATE":
                        strTemp = vendorBLL.UpdateVendorByWebService(vendorList);
                        break;
                }
            }
            catch (Exception ex)
            {
                EdiLogInfo edilogInfo = new EdiLogInfo();
                edilogInfo.WhID = "";
                edilogInfo.LogDate = DateTime.Now;
                edilogInfo.IsSuccess = "异常";
                edilogInfo.LogDescr = "XML数据组织错误:" + ex.Message;
                edilogInfo.UserID = "CEAWebService";
                edilogInfo.Udf1 = "接口数据组织";
                edilogInfo.Udf3 = "承运商资料";
                new EDIService().InsertEdiLogInfo(edilogInfo);
                strTemp = ex.Message;
            }
            return strTemp;
        }

        private void InitPubParasInfo()
        {
            this.pubParasInfo = new PubParasInfo();
            this.pubParasInfo.UserID = "CEAWebService";
            this.pubParasInfo.UserLanguage = "zh-cn";
            this.pubParasInfo.CurrentWH = "";
        }

        private OrdersInfo SetOrdersInfo(XmlNode node, string ownerID, string toOwnerID)
        {
            OrdersInfo ordersInfo = new OrdersInfo();
            if (node["EXTERN_ORDER_ID"] == null)
            {
                throw new Exception("文档中未匹配到 EXTERN_ORDER_ID");
            }
            ordersInfo.ExternOrderID = node["EXTERN_ORDER_ID"].Attributes["value"].Value;
            if (node["OWNER_ID"] == null)
            {
                throw new Exception("文档中未匹配到 OWNER_ID");
            }
            if (string.IsNullOrEmpty(node["OWNER_ID"].Attributes["value"].Value))
            {
                throw new Exception("OWNER_ID 为必填 不能为空");
            }
            ordersInfo.OwnerID = ownerID;
            if (ordersInfo.OwnerID == "1000")
            {
                ordersInfo.WhID = "wh2.";
            }
            else
            {
                if ((ordersInfo.OwnerID != "3000") && (ordersInfo.OwnerID != "9000"))
                {
                    throw new Exception("无法匹配到" + ordersInfo.OwnerID + "公司所属的仓库名称");
                }
                ordersInfo.WhID = "wh1.";
            }
            if (node["TYPE"] == null)
            {
                throw new Exception("文档中未匹配到 TYPE");
            }
            ordersInfo.Udf10 = node["TYPE"].Attributes["value"].Value;
            if (node["REQUEST_SHIP_DATE"] == null)
            {
                throw new Exception("文档中未匹配到 DELIVERY_DATE");
            }
            if (string.IsNullOrEmpty(node["REQUEST_SHIP_DATE"].Attributes["value"].Value))
            {
                ordersInfo.RequestedShipDate = DateTime.Now;
            }
            else
            {
                ordersInfo.RequestedShipDate = DateTime.Parse(node["REQUEST_SHIP_DATE"].Attributes["value"].Value);
            }
            if (node["CONSIGNEE_ID"] == null)
            {
                throw new Exception("文档中未匹配到 CONSIGNEE_ID");
            }
            ordersInfo.ConsigneeID = node["CONSIGNEE_ID"].Attributes["value"].Value;
            if (node["REMARK"] == null)
            {
                throw new Exception("文档中未匹配到 REMARK");
            }
            ordersInfo.Remark = node["REMARK"].Attributes["value"].Value;
            ordersInfo.Remark2 = "";
            ordersInfo.Type = "Transfer";
            DbConfigBLL dbConfigBll = new DbConfigBLL();
            DbConfigInfo dbconfigInfo = new DbConfigInfo();
            if (toOwnerID == "1000")
            {
                dbconfigInfo = (DbConfigInfo) dbConfigBll.GetDbConfigByDbLoginID("wh2");
            }
            else
            {
                dbconfigInfo = (DbConfigInfo) dbConfigBll.GetDbConfigByDbLoginID("wh1");
            }
            if (dbconfigInfo == null)
            {
                throw new Exception("无法匹配到" + toOwnerID + "公司所属的仓库名称");
            }
            ordersInfo.DestWhDbID = dbconfigInfo.WhDbID.ToString();
            ordersInfo.DeliveryDate = DateTime.Now;
            ordersInfo.OrderDate = DateTime.Now;
            ordersInfo.Priority = "3";
            ordersInfo.OrderGroup = "";
            ordersInfo.OpenQty = 0M;
            ordersInfo.Status = "New";
            ordersInfo.BillToID = "";
            ordersInfo.DepartureDate = DateTime.Now;
            ordersInfo.Door = "";
            ordersInfo.Route = "";
            ordersInfo.Stop = "";
            ordersInfo.TransportationMode = "LTL";
            ordersInfo.IncoTerms = "CFR";
            ordersInfo.ContainerType = "DC20FT";
            ordersInfo.ContainerQty = 0M;
            ordersInfo.HandlingType = "Standard";
            ordersInfo.BatchFlag = "N";
            ordersInfo.ShipTogether = "N";
            ordersInfo.EnablePacking = "N";
            ordersInfo.OrderValue = 0M;
            ordersInfo.UpdateSource = "";
            ordersInfo.IsActive = "Y";
            ordersInfo.CreatedBy = "CEAWebService";
            ordersInfo.CreatedDate = DateTime.Now;
            ordersInfo.UpdatedBy = "CEAWebService";
            ordersInfo.UpdatedDate = DateTime.Now;
            ordersInfo.CoreReleaseID = "";
            ordersInfo.IsDeclartion = "N";
            ordersInfo.ActualWeight = 0M;
            ordersInfo.PrintCount = 0;
            ordersInfo.IsICancel = "N";
            ordersInfo.IsCod = "N";
            ordersInfo.IsInvoicePrint = "N";
            ordersInfo.OrderDetailInfos = new List<OrderDetailInfo>();
            XmlNodeList detail = node.ChildNodes;
            int i = 0;
            foreach (XmlNode detailnode in detail)
            {
                if (detailnode.Name == "DETAIL")
                {
                    i++;
                    OrderDetailInfo orderDetailInfo = new OrderDetailInfo();
                    if (detailnode["SKU_ID"] == null)
                    {
                        throw new Exception("文档中未匹配到 SKU_ID");
                    }
                    if (string.IsNullOrEmpty(detailnode["SKU_ID"].Attributes["value"].Value))
                    {
                        throw new Exception("SKU_ID 为必填 不能为空");
                    }
                    orderDetailInfo.SkuID = detailnode["SKU_ID"].Attributes["value"].Value;
                    if (detailnode["ORIGINAL_QTY"] == null)
                    {
                        throw new Exception("文档中未匹配到 ORIGINAL_QTY");
                    }
                    if (string.IsNullOrEmpty(detailnode["ORIGINAL_QTY"].Attributes["value"].Value))
                    {
                        throw new Exception("ORIGINAL_QTY 为必填 不能为空");
                    }
                    orderDetailInfo.OriginalQty = decimal.Parse(detailnode["ORIGINAL_QTY"].Attributes["value"].Value);
                    if (detailnode["EXTERN_LINE_ID"] == null)
                    {
                        throw new Exception("文档中未匹配到 EXTERN_LINE_ID");
                    }
                    if (string.IsNullOrEmpty(detailnode["EXTERN_LINE_ID"].Attributes["value"].Value))
                    {
                        throw new Exception("EXTERN_LINE_ID 为必填 不能为空");
                    }
                    orderDetailInfo.ExternLineID = detailnode["EXTERN_LINE_ID"].Attributes["value"].Value;
                    if (detailnode["UDF1"] == null)
                    {
                        throw new Exception("文档中未匹配到 UDF1");
                    }
                    orderDetailInfo.Udf1 = detailnode["UDF1"].Attributes["value"].Value;
                    if (detailnode["UDF2"] == null)
                    {
                        throw new Exception("文档中未匹配到 UDF2");
                    }
                    orderDetailInfo.Udf2 = detailnode["UDF2"].Attributes["value"].Value;
                    if (detailnode["UDF3"] == null)
                    {
                        throw new Exception("文档中未匹配到 UDF3");
                    }
                    orderDetailInfo.Udf3 = detailnode["UDF3"].Attributes["value"].Value;
                    if (detailnode["UDF4"] == null)
                    {
                        throw new Exception("文档中未匹配到 UDF4");
                    }
                    orderDetailInfo.Udf4 = detailnode["UDF4"].Attributes["value"].Value;
                    if (detailnode["UDF5"] == null)
                    {
                        throw new Exception("文档中未匹配到 UDF5");
                    }
                    orderDetailInfo.Udf5 = detailnode["UDF5"].Attributes["value"].Value;
                    orderDetailInfo.LotAttr01 = "";
                    orderDetailInfo.LotAttr02 = "";
                    orderDetailInfo.LotAttr03 = "";
                    orderDetailInfo.LotAttr04 = "";
                    orderDetailInfo.LotAttr05 = "";
                    orderDetailInfo.LotAttr06 = "";
                    orderDetailInfo.LotAttr07 = "";
                    orderDetailInfo.LotAttr08 = "";
                    orderDetailInfo.LotAttr09 = "";
                    orderDetailInfo.LotAttr10 = "";
                    orderDetailInfo.UomID = "EA";
                    orderDetailInfo.Length = 0f;
                    orderDetailInfo.Width = 0f;
                    orderDetailInfo.Height = 0f;
                    orderDetailInfo.Cube = 0f;
                    orderDetailInfo.GrossWGT = 0f;
                    orderDetailInfo.NetWGT = 0f;
                    orderDetailInfo.UnitPrice = 0.0;
                    orderDetailInfo.ExtendedPrice = 0.0;
                    orderDetailInfo.VendorID = "";
                    orderDetailInfo.LineID = i * 10;
                    orderDetailInfo.ExternOrderID = ordersInfo.ExternOrderID;
                    orderDetailInfo.AltSkuID = "";
                    orderDetailInfo.OwnerID = ordersInfo.OwnerID;
                    orderDetailInfo.OpenQty = 0M;
                    orderDetailInfo.ShippedQty = 0M;
                    orderDetailInfo.AdjustedQty = 0M;
                    orderDetailInfo.PreallocatedQty = 0M;
                    orderDetailInfo.AllocatedQty = 0M;
                    orderDetailInfo.PickedQty = 0M;
                    orderDetailInfo.PackID = "STD";
                    orderDetailInfo.PickCode = "";
                    orderDetailInfo.CartonGroup = "";
                    orderDetailInfo.LpnID = "";
                    orderDetailInfo.Status = "New";
                    orderDetailInfo.Tax01 = 0.0;
                    orderDetailInfo.Tax02 = 0.0;
                    orderDetailInfo.UpdateSource = "";
                    orderDetailInfo.ProductWeight = 0.0;
                    orderDetailInfo.ProductCube = 0.0;
                    orderDetailInfo.CartonQtyBreak = 0;
                    orderDetailInfo.QcRequired = "N";
                    orderDetailInfo.QcAutoAdjust = "N";
                    orderDetailInfo.ShipGroup01 = "Y";
                    orderDetailInfo.ShipGroup02 = "N";
                    orderDetailInfo.ShipGroup03 = "N";
                    orderDetailInfo.IsSubstitute = 0;
                    orderDetailInfo.OkToSubstitute = 0;
                    orderDetailInfo.AllocateRuleID = "STD";
                    orderDetailInfo.PreallocateRuleID = "STD";
                    orderDetailInfo.SkuRotation = "Lot";
                    orderDetailInfo.ShelfLife = 0;
                    orderDetailInfo.ComponentQty = 0M;
                    orderDetailInfo.Lot = "";
                    orderDetailInfo.EffectiveDate = DateTime.Now;
                    orderDetailInfo.OrigCaseQty = 0M;
                    orderDetailInfo.OrigPalletQty = 0M;
                    orderDetailInfo.QtyIntransit = 0M;
                    orderDetailInfo.WpReleased = "N";
                    orderDetailInfo.MinShipperCent = 0;
                    orderDetailInfo.CreatedBy = "CEAWebService";
                    orderDetailInfo.CreatedDate = DateTime.Now;
                    orderDetailInfo.UpdatedBy = "CEAWebService";
                    orderDetailInfo.UpdatedDate = DateTime.Now;
                    orderDetailInfo.DeclarationQty = 0M;
                    orderDetailInfo.NumberLost = 0M;
                    orderDetailInfo.ReceivedQty = 0M;
                    orderDetailInfo.BatchFlag = "N";
                    ordersInfo.OrderDetailInfos.Add(orderDetailInfo);
                }
            }
            return ordersInfo;
        }

        private ReceiptInfo SetReceiptInfo(XmlNode node, string ownerID)
        {
            ReceiptInfo receiptInfo = new ReceiptInfo();
            if (node["EXTERN_ORDER_ID"] == null)
            {
                throw new Exception("文档中未匹配到 EXTERN_ORDER_ID");
            }
            if (string.IsNullOrEmpty(node["EXTERN_ORDER_ID"].Attributes["value"].Value))
            {
                throw new Exception("EXTERN_ORDER_ID 为必填 不能为空");
            }
            receiptInfo.ExternalReceiptID = node["EXTERN_ORDER_ID"].Attributes["value"].Value;
            if (node["OWNER_ID"] == null)
            {
                throw new Exception("文档中未匹配到 OWNER_ID");
            }
            if (string.IsNullOrEmpty(node["OWNER_ID"].Attributes["value"].Value))
            {
                throw new Exception("OWNER_ID 为必填 不能为空");
            }
            receiptInfo.OwnerID = ownerID;
            if (receiptInfo.OwnerID == "1000")
            {
                receiptInfo.WhID = "wh2.";
            }
            else
            {
                if ((receiptInfo.OwnerID != "3000") && (receiptInfo.OwnerID != "9000"))
                {
                    throw new Exception("无法匹配到" + receiptInfo.OwnerID + "公司所属的仓库名称");
                }
                receiptInfo.WhID = "wh1.";
            }
            if (node["CONSIGNEE_ID"] == null)
            {
                throw new Exception("文档中未匹配到 CONSIGNEE_ID");
            }
            receiptInfo.Udf5 = node["CONSIGNEE_ID"].Attributes["value"].Value;
            if (node["TYPE"] == null)
            {
                throw new Exception("文档中未匹配到 TYPE");
            }
            receiptInfo.Udf10 = node["TYPE"].Attributes["value"].Value;
            if (node["REMARK"] == null)
            {
                throw new Exception("文档中未匹配到 REMARK");
            }
            receiptInfo.Remark = node["REMARK"].Attributes["value"].Value;
            if (node["REQUEST_SHIP_DATE"] == null)
            {
                throw new Exception("文档中未匹配到 DELIVERY_DATE");
            }
            if (string.IsNullOrEmpty(node["REQUEST_SHIP_DATE"].Attributes["value"].Value))
            {
                receiptInfo.ExpectedReceiptDate = DateTime.Now;
            }
            else
            {
                receiptInfo.ExpectedReceiptDate = DateTime.Parse(node["REQUEST_SHIP_DATE"].Attributes["value"].Value);
            }
            receiptInfo.WarehouseRef = "";
            receiptInfo.VendorID = "";
            receiptInfo.ArrivalDate = DateTime.Now;
            receiptInfo.ReceiptType = "Return";
            receiptInfo.PoID = "";
            receiptInfo.PackingSlipNumber = "";
            receiptInfo.Rma = "";
            receiptInfo.ReceiptDate = DateTime.Now;
            receiptInfo.OpenQty = 0M;
            receiptInfo.Status = "New";
            receiptInfo.AdviceNumber = "";
            receiptInfo.TransportationMode = "LTL";
            receiptInfo.IncoTerms = "CFR";
            receiptInfo.PaymentTerm = "Cash";
            receiptInfo.ContainerType = "DC20FT";
            receiptInfo.ContainerQty = 0M;
            receiptInfo.LottableMatchRequired = "N";
            receiptInfo.IsPalletized = "N";
            receiptInfo.IsActive = "Y";
            receiptInfo.CoreReleaseID = "";
            receiptInfo.IsDeclartion = "N";
            receiptInfo.SAPAuthentication = "Y";
            receiptInfo.CreatedBy = "CEAWebService";
            receiptInfo.CreatedDate = DateTime.Now;
            receiptInfo.UpdatedBy = "CEAWebService";
            receiptInfo.UpdatedDate = DateTime.Now;
            receiptInfo.ReceiptDetailInfos = new List<ReceiptDetailInfo>();
            XmlNodeList detail = node.ChildNodes;
            int i = 0;
            foreach (XmlNode detailnode in detail)
            {
                if (detailnode.Name == "DETAIL")
                {
                    i++;
                    ReceiptDetailInfo receiptDetailInfo = new ReceiptDetailInfo();
                    receiptDetailInfo.ReceiptLot = new ReceiptLotInfo();
                    if (detailnode["SKU_ID"] == null)
                    {
                        throw new Exception("文档中未匹配到 SKU_ID");
                    }
                    if (string.IsNullOrEmpty(detailnode["SKU_ID"].Attributes["value"].Value))
                    {
                        throw new Exception("SKU_ID 为必填 不能为空");
                    }
                    receiptDetailInfo.SkuID = detailnode["SKU_ID"].Attributes["value"].Value;
                    if (detailnode["EXTERN_LINE_ID"] == null)
                    {
                        throw new Exception("文档中未匹配到 EXTERN_LINE_ID");
                    }
                    receiptDetailInfo.ExternLineID = detailnode["EXTERN_LINE_ID"].Attributes["value"].Value;
                    if (detailnode["ORIGINAL_QTY"] == null)
                    {
                        throw new Exception("文档中未匹配到 EXPECTED_QTY");
                    }
                    if (string.IsNullOrEmpty(detailnode["ORIGINAL_QTY"].Attributes["value"].Value))
                    {
                        throw new Exception("ORIGINAL_QTY 为必填 不能为空");
                    }
                    receiptDetailInfo.ExpectedQty = decimal.Parse(detailnode["ORIGINAL_QTY"].Attributes["value"].Value);
                    if (detailnode["UDF1"] == null)
                    {
                        throw new Exception("文档中未匹配到 UDF1");
                    }
                    receiptDetailInfo.Udf1 = detailnode["UDF1"].Attributes["value"].Value;
                    if (detailnode["UDF2"] == null)
                    {
                        throw new Exception("文档中未匹配到 UDF2");
                    }
                    receiptDetailInfo.Udf2 = detailnode["UDF2"].Attributes["value"].Value;
                    if (detailnode["UDF3"] == null)
                    {
                        throw new Exception("文档中未匹配到 UDF3");
                    }
                    receiptDetailInfo.Udf3 = detailnode["UDF3"].Attributes["value"].Value;
                    if (detailnode["UDF4"] == null)
                    {
                        throw new Exception("文档中未匹配到 UDF4");
                    }
                    receiptInfo.Udf4 = detailnode["UDF4"].Attributes["value"].Value;
                    if (detailnode["UDF5"] == null)
                    {
                        throw new Exception("文档中未匹配到 UDF5");
                    }
                    receiptInfo.Udf3 = detailnode["UDF5"].Attributes["value"].Value;
                    receiptDetailInfo.GrossWgt = 0f;
                    receiptDetailInfo.NetWgt = 0f;
                    receiptDetailInfo.UnitPrice = 0f;
                    receiptDetailInfo.ReceiptLot.LotAttr01 = "";
                    receiptDetailInfo.ReceiptLot.LotAttr02 = "";
                    receiptDetailInfo.ReceiptLot.LotAttr03 = "";
                    receiptDetailInfo.ReceiptLot.LotAttr04 = "";
                    receiptDetailInfo.ReceiptLot.LotAttr05 = "";
                    receiptDetailInfo.ReceiptLot.LotAttr06 = "";
                    receiptDetailInfo.ReceiptLot.LotAttr07 = "";
                    receiptDetailInfo.ReceiptLot.LotAttr08 = "";
                    receiptDetailInfo.ReceiptLot.LotAttr09 = "";
                    receiptDetailInfo.ReceiptLot.LotAttr10 = "";
                    receiptDetailInfo.Length = 0f;
                    receiptDetailInfo.Width = 0f;
                    receiptDetailInfo.Height = 0f;
                    receiptDetailInfo.Cube = 0f;
                    receiptDetailInfo.UomID = "EA";
                    receiptDetailInfo.VendorID = receiptInfo.VendorID;
                    receiptDetailInfo.ExtendedPrice = receiptDetailInfo.UnitPrice * float.Parse(receiptDetailInfo.ExpectedQty.ToString());
                    receiptDetailInfo.ReceiptLineID = i * 10;
                    receiptDetailInfo.OwnerID = receiptInfo.OwnerID;
                    receiptDetailInfo.ExternReceiptID = receiptInfo.ExternalReceiptID;
                    receiptDetailInfo.PoID = "";
                    receiptDetailInfo.PoLineID = 0;
                    receiptDetailInfo.AltSkuID = "";
                    receiptDetailInfo.LpnID = "";
                    receiptDetailInfo.Status = receiptInfo.Status;
                    receiptDetailInfo.ReceivedDate = DateTime.Now;
                    receiptDetailInfo.AdjustedQty = 0M;
                    receiptDetailInfo.ReceivedQty = 0M;
                    receiptDetailInfo.RejectedQty = 0M;
                    receiptDetailInfo.PackID = "STD";
                    receiptDetailInfo.ToLoc = "Stage";
                    receiptDetailInfo.ToLot = "";
                    receiptDetailInfo.ToLpnID = "";
                    receiptDetailInfo.ConditionCode = "OK";
                    receiptDetailInfo.ReceiptDate = receiptInfo.ReceiptDate;
                    receiptDetailInfo.ExternalLot = "";
                    receiptDetailInfo.CaseCnt = 0M;
                    receiptDetailInfo.InnerPack = 0M;
                    receiptDetailInfo.Pallet = 0M;
                    receiptDetailInfo.OtherUnit1 = 0f;
                    receiptDetailInfo.OtherUnit2 = 0f;
                    receiptDetailInfo.EffectiveDate = DateTime.Now;
                    receiptDetailInfo.QcRequired = "N";
                    receiptDetailInfo.QcInspectedQty = 0M;
                    receiptDetailInfo.QcAutoAdjust = "N";
                    receiptDetailInfo.DeclarationQty = 0M;
                    receiptDetailInfo.CreatedBy = "CEAWebService";
                    receiptDetailInfo.CreatedDate = DateTime.Now;
                    receiptDetailInfo.UpdatedBy = "CEAWebService";
                    receiptDetailInfo.UpdatedDate = DateTime.Now;
                    receiptInfo.ReceiptDetailInfos.Add(receiptDetailInfo);
                }
            }
            return receiptInfo;
        }

        private bool UserAuthentication(string userName, string password)
        {
            bool isAuthentication = false;
            try
            {
                string struserName = ConfigurationManager.AppSettings["CEA_USER_ID"];
                string strPassword = ConfigurationManager.AppSettings["CEA_PASSWORD"];
                if ((userName == struserName) && (password == strPassword))
                {
                    return true;
                }
                isAuthentication = false;
            }
            catch (Exception ex)
            {
                EdiLogInfo edilogInfo = new EdiLogInfo();
                edilogInfo.LogDate = DateTime.Now;
                edilogInfo.IsSuccess = "异常";
                edilogInfo.LogDescr = "用户名密码错误:" + ex.Message;
                edilogInfo.UserID = "CEAWebService";
                edilogInfo.Udf1 = "访问接口";
                edilogInfo.Udf2 = "用户名:" + userName;
                edilogInfo.Udf3 = "客户资料";
                edilogInfo.Udf4 = "密码:" + password;
                new EDIService().InsertEdiLogInfo(edilogInfo);
                throw new Exception("Error");
            }
            return isAuthentication;
        }
    }
}

